﻿Imports AdventureWorks.BusinessObjects
Imports System.Linq.Expressions

Namespace Parameters

    Public Class CurrentProductParameter
        Inherits Catalyst.Web.DynamicData.DynamicExpressionParameterBase


        Public Overrides Function GetLambdaExpression(ByVal itType As System.Type) As System.Linq.Expressions.LambdaExpression

            If itType IsNot GetType(Product) Then
                Throw New ArgumentException("CurrentProductParameter only works with Product type")
            End If

            Dim lambda As Expression(Of Func(Of Product, Boolean)) = Function(x As Product) (x.SellStartDate <= Date.Now) _
                                                                                    AndAlso (x.SellEndDate Is Nothing OrElse CType(x.SellEndDate >= Date.Now, Boolean))

            Return lambda
        End Function

    End Class

End Namespace
